﻿using System;
using System.Collections.Generic;
using System.Text;
using QuanLyHocSinh.HeThongXuLy;
using System.Data;
using System.Windows.Forms;

namespace QuanLyHocSinh.HeThongLuuTru
{
    class LopHocDAO
    {
        public static bool ThemLopHoc(LopHocDTO lh)
        {
            try
            {
                //tao cau truy van va thuc thi cau truy van
                string sql = "insert into LOPHOC(TunLop, KhoiLop, LopChuyen, PhongHoc) values ('" +
                lh.TenLop + "'," +
                lh.KhoiLop + ",'" +
                lh.LopChuyen + "','" +
                lh.PhongHoc + "')";
                DataAccess.ExecNonQuery(sql);
                return true;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static bool SuaLopHoc(LopHocDTO lh)
        {
            try
            {
                // Tao cau truy van & thuc thi caun truy van
                string sql = "update LOPHOC set TenLop='" +
                    lh.TenLop + "', KhoiLop=" +
                    lh.KhoiLop + ", LopChuyen='" +
                    lh.LopChuyen + "', PhongHoc='" +
                    lh.PhongHoc + "' where MaLop=" +
                    lh.MaLop;

                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
 

        }

        public static bool XoaLopHoc(LopHocDTO lh)
        {
            try
            {
                // Tao cau truy van & thuc thi caun truy van
                string sql = "delete from LOPHOC where MaLop=" +
                    lh.TenLop;

                DataAccess.ExecNonQuery(sql);
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }


        }

        public static DataTable DanhSachLopHoc()
        {
            string sql = "SELECT * FROM LOPHOC";
            return DataAccess.ExecQuery(sql);
        }
    }
}
